from flask import current_app
from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand
from info import creat_app, set_up_loglevel
from info import db
from info import models
from info.models import User

app = creat_app("development")
set_up_loglevel('development')


manager = Manager(app)
Migrate(app, db)
manager.add_command('db', MigrateCommand)

@manager.option("-n", "-name", dest = "name")
@manager.option("-p", "-password", dest = "password")
def create_super_user(name, password):
    user = User()
    try:
        user.mobile = name
        user.nick_name = name
        user.password = password
        user.is_admin = True
        db.session.add(user)
        db.session.commit()
    except Exception as error:
        db.session.rollback()
        print("创建失败")
        # current_app.logger.error(error)
    print('创建管理员成功')

if __name__ == '__main__':
    # print(app.url_map)
    manager.run()
